﻿@using Gurux.DLMS.AMI.Client.Pages.Config;
@using Gurux.DLMS.AMI.Shared.DIs
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Gurux.DLMS.AMI.Shared.DTOs.Authentication
@using Gurux.DLMS.AMI.Shared
@using Gurux.DLMS.AMI.Shared.Enums
@using Gurux.DLMS.AMI.Shared.DTOs

@inject NavigationManager NavigationManager
@inject HttpClient Http
@inject IGXNotifier Notifier
@implements IGXConfigUpdate

<!--If user adds a new item or modifies the existing one.-->
@if (string.Compare(Action, "Add", true) == 0 || (Id != null && Path != null && string.Compare(Action, "Edit", true) == 0))
{
    if (string.Compare(Path, "config/Manufacturer", true) == 0)
    {
        <ManufacturerTab Action="@Action" Id="@Id"></ManufacturerTab>
    }
}
else
{
    <TabControl Active="@Path" SelectionChanged="@SelectionChanged">
        <TabTextTemplate>
            <span class=@context.Icon aria-hidden="true"></span>
            @context.Text
        </TabTextTemplate>
        <ChildContent>
            <AuthorizeView Roles=@GXRoles.ToString(GXRoles.Admin, GXRoles.ManufacturerManager)>
                <TabPage Path="config/Manufacturer" Text=@Properties.Resources.Manufacturers Icon="oi oi-share-boxed">
                    <div style="position: relative; width: 100%; ">
                        <Manufacturers Parent="this" @ref="_updater"></Manufacturers>
                    </div>
                </TabPage>
            </AuthorizeView>
        </ChildContent>
    </TabControl>
}
<br />
@code {

    /// <summary>
    /// Parent component.
    /// </summary>
    [Parameter]
    public Gurux.DLMS.AMI.Client.Pages.Config.Configurations? Parent { get; set; }

    IGXConfigUpdate? _updater;

    /// <inheritdoc/>
    public void Update()
    {
        _updater?.Update();
    }

    /// <summary>
    /// User action.
    /// </summary>
    [Parameter]
    public string? Action { get; set; }
    /// <summary>
    /// Selected item.
    /// </summary>
    [Parameter]
    public Guid? Id { get; set; }

    [Parameter]
    public string? Path { get; set; }

    /// <summary>
    /// User has selected a new tab.
    /// </summary>
    /// <param name="page">Tab page.</param>
    void SelectionChanged(TabPage page)
    {
        Path = page.Path;
    }  
}

